package com.cn.wanix.util;

import java.text.SimpleDateFormat;
import java.util.Date;

public class Tool {
    private Tool() {
    }

    public static int stringToInt(String value) {
        try {
            return Integer.parseInt(value);
        } catch (Exception e) {

        }
        return 0;
    }
    public static Float stringToFloat(String value) {
        try {
            return Float.parseFloat(value);
        } catch (Exception e) {

        }
        return 0F;
    }
    public static int enableToInt(String value) {
        try {
            return Integer.parseInt(value);
        } catch (Exception e) {

        }
        return -1;
    }
    public static int pageSizeToInt(String value) {
        try {
            return Integer.parseInt(value);
        } catch (Exception e) {

        }
        return 10;
    }

    public static String nullToString(String value) {
        return value == null || value.equals("undefined") ? "" : value;
    }

    public static int pageToInt(String value) {
        try {
            return Integer.parseInt(value);
        } catch (Exception e) {

        }
        return 1;
    }

    public static Date stringToDate(String dateString, String fmt) {
        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat(fmt);
        try {
            return dateFormat.parse(dateString);
        } catch (Exception e) {

        }
        return date;
    }
}
